import java.io.*;

public class getCode{

	int value;
	String TempAddr = "abcd",addr;
	String TempData = "ab",data;	
	Emulator emu;
	
	public getCode(Emulator emulator)
	{
		emu = emulator;
		try{gettingCode();}
		catch (IOException e){
			System.out.println("file error. ");
			System.exit(0);
		}
		
	}
   
	public void gettingCode() throws IOException{
		
		
		{
			
			FileReader input = new FileReader("test.res");
			
			
			while((value=input.read())!= -1)
			{
	         if(value == 13 || value == 10)
	        	continue;
	         else{
	          if(value == 97){
	        	  input.read(); // read the char t
	        	  input.read(); // read the space
	        	  
	        	  TempAddr = TempAddr.replace(TempAddr.charAt(0),(char)input.read());
	        	  TempAddr = TempAddr.replace(TempAddr.charAt(1),(char)input.read());
	        	  TempAddr = TempAddr.replace(TempAddr.charAt(2),(char)input.read());
	        	  TempAddr = TempAddr.replace(TempAddr.charAt(3),(char)input.read());
	              addr = TempAddr;
	              TempAddr="abcd";
	              
	           }
	           else{
	        	  
	        	 TempData = TempData.replace(TempData.charAt(0),(char)value);  
	        	 TempData = TempData.replace(TempData.charAt(1),(char)input.read());
	        	 data = TempData;
	        	 TempData = "ab";
	        	 
	        	 emu.ram.setRAM(Short.valueOf(data,16),Integer.valueOf(addr,16));
	        	 addr = Integer.toString(Integer.parseInt(addr)+1);
	        	 
	        	
	        	 
	           }	   
	        	
	        	
	         }
				

			}
			input.close();
		}
		
		
	}
	
	
}
